package day_2022_12_to_3.year2023;

import java.util.HashMap;
import java.util.Map;

/**
 * @author haomin
 * @date 2023/04/13 20:50
 **/
public class Day4_13_Num2404 {
    class Solution {
        public int mostFrequentEven(int[] nums) {
            Map<Integer, Integer> map = new HashMap<>();
            int res = -1, maxVal = 0;
            for (int i = 0; i < nums.length; i++) {
                if (nums[i] % 2 == 0) {
                    int val = map.getOrDefault(nums[i], 0) + 1;
                    if (maxVal < val) {
                        maxVal = val;
                        res = nums[i];
                    } else if (maxVal == val) {
                        res = Math.min(res, nums[i]);
                    }
                    map.put(nums[i], val);
                }
            }
            return res;
        }
    }
}